package bean;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import oracle.jdbc.pool.OracleDataSource;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author BAGUS
 */
public class UserGasElpiji {
    private String idUser;
    private String namaUser;
    private String alamatUser;
    private String noTelepon;
    private String Status;
    private String username;
    private String password;
    String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:XE";
    String userid = "hr"; // gantikan dengan username anda
    String pass = "hr"; // gantikan dengan password anda

    public String getIdUser() {
        return idUser;
    }

    public void setIdUser(String idUser) {
        this.idUser = idUser;
    }

    public String getNamaUser() {
        return namaUser;
    }

    public void setNamaUser(String namaUser) {
        this.namaUser = namaUser;
    }

    public String getAlamatUser() {
        return alamatUser;
    }

    public void setAlamatUser(String alamatUser) {
        this.alamatUser = alamatUser;
    }

    public String getNoTelepon() {
        return noTelepon;
    }

    public void setNoTelepon(String noTelepon) {
        this.noTelepon = noTelepon;
    }

    public String getStatus() {
        return Status;
    }

    public void setStatus(String Status) {
        this.Status = Status;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
    
    public boolean bandingUser(){
        try {
            Connection connection = null;
            OracleDataSource ds;
            ds = new OracleDataSource();
            ds.setURL(jdbcUrl);
            ds.setPassword(pass);
            ds.setUser(userid);
            connection = (Connection) ds.getConnection();
            Statement statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery("select username, password from usergaselpiji "
                    + "where username = '"
                    + getUsername() + "' and password = "
                    + "'"+ getPassword() + "'");
            while (resultSet.next() == true) {
                return true;
            }
            return false;
        } catch (SQLException e) {
// perform error handling here
            System.out.println("error :" + e.getMessage());
            return false;
        }
    }
    
    public String bandingStatusUser() {
        try {
            Connection connection = null;
            OracleDataSource ds;
            ds = new OracleDataSource();
            ds.setURL(jdbcUrl);
            ds.setPassword(pass);
            ds.setUser(userid);
            connection = (Connection) ds.getConnection();
            Statement statement = connection.createStatement();
            String hasil = null;
            ResultSet resultSet = statement.executeQuery("select jenis from usergaselpiji where username = '" + getUsername() + "'");
            while (resultSet.next()) {
                if (resultSet.getString("jenis") == null) {
                    hasil = "0";
                } else {
                    hasil = resultSet.getString("jenis");
                }
            }
            if ("0".equals(hasil)) {
                return "0";
            } else {
                setStatus(hasil);
                return hasil;
            }
        } catch (SQLException e) {
// perform error handling here
            System.out.println("error :" + e.getMessage());
            return "0";
        }
    }
}
